package com.neo;

import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.springframework.web.bind.annotation.*;

import java.util.Iterator;
import java.util.List;

/**
 * @Author: hredis
 * @Date: 2020/10/28 17:39
 */
@RestController
@RequestMapping("/test")
//@CrossOrigin(origins = {"http://manage.mall.com"},allowedHeaders = {"x-requested-with","context-type"},allowCredentials = "true")
public class HelloController {

    //简单请求测试
    @RequestMapping("/server")
    public Result server(){
        return new Result("hello, i'm the server");
    }

    //复杂请求测试
    @PostMapping("/postjson")
    public Result postjson(@RequestBody User user){
        return new Result("post json method : " + user.getName());
    }

    //带cookie的请求
    @GetMapping("/getCookie")
    public Result getCookie(@CookieValue("cookie1") String cookie1){
        return new Result(cookie1);
    }

    //带header的请求
    @GetMapping("/getHeader")
    public Result getHeader(@RequestHeader(value = "x-header1",defaultValue = "")String header1,
                            @RequestHeader(value = "x-header2",defaultValue = "")String header2){
        return new Result(Joiner.on(" ").join("setHeader方法",header1, header2));
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    class Result{
        private Object data;
    }

}
